<?php

namespace App\Helpers;

/**
 * Class DataHelper
 * @package App\Helpers
 */
class DataHelper
{
    private $code;
    private $msg;
    private $data=[];

    /**
     * @param $code
     * @param $msg
     * @param array $data
     * 设置通用的响应数据
     */
    public function set($code,$msg,$data=[]){
        $this->code=$code;
        $this->msg=$msg;
        if(!empty($data)){
            $this->data=$data;
        }
    }

    /**
     * @param array $data
     * 设置请求成功的响应数据
     */
    public function setSuccess($data=[]){
        $this->code=SystemHelper::SUCCESS;
        $this->msg=SystemHelper::SUCCESS_MSG;
        if(!empty($data)){
            $this->data=$data;
        }
    }

    /**
     * @return array
     * 不带数据的返回
     */
    public function returnMsg(){
        return ['code' => $this->code,'msg' => $this->msg];
    }

    /**
     * @return array
     * 包含数据的返回
     */
    public function returnData(){
        return ['code' => $this->code,'msg' => $this->msg,'data' => $this->data];
    }
}